package main

import (
	"database/sql"
	"fmt"
	"time"

	_ "github.com/go-sql-driver/mysql"
)

func main() {
	driverName := "mysql"
	dsn := "golang:zxc,./123@tcp(43.139.115.142:3306)/user?charset=utf8mb4&loc=Local&parseTime=true"
	db, err := sql.Open(driverName, dsn)
	if err != nil {

		fmt.Println(err)
		return
	}
	defer db.Close()
	if err = db.Ping(); err != nil {
		fmt.Println(err)
		return
	}

	rows, err := db.Query("select * from user")
	defer rows.Close()
	if err != nil {
		fmt.Println(err)
		return
	}
	for rows.Next() {
		var (
			id       int64
			name     string
			password string
			sex      bool
			birthday *time.Time
			addr     string
			tel      string
		)
		err := rows.Scan(&id, &name, &password, &sex, &birthday, &addr, &tel)
		if err != nil {
			fmt.Println(err)
			break
		}
		fmt.Println(id, name, password, sex, birthday, addr, tel)
	}

}
